package com.example.support.profile;

import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.example.support.profile.model.Profile;
import com.example.support.profile.service.ProfileService;
import com.example.support.spring.SpringContextHolder;

public class ProfileHelper {

	public static String lookupValue(String name) {
		Profile profile = SingletonHolder.profileService.findProfileByName(name);
		return profile == null ? null : profile.getValue();
	}

	public static Map<String, Object> lookupValueAsMap(String name) {
		String value = lookupValue(name);
		return JSON.<Map<String, Object>>parseObject(value, Map.class);
	}

	private static class SingletonHolder {
		static final ProfileService profileService = SpringContextHolder.getContext().getBean(ProfileService.class);
	}

}
